package com.sti.platform.dao.impl;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.aisino.core.dao.BaseDao;
import com.aisino.tools.enums.PageEnum;
import com.aisino.tools.enums.QlEnum;
import com.aisino.tools.util.page.Page;
import com.sti.platform.dao.NoticeDao;
import com.sti.platform.model.Notice;

@Repository
public class NoticeDaoImpl extends BaseDao implements NoticeDao{

	/**不加任何条件获取全部数据*/
	@Override
	public List<Notice> getAllNotice() {
		String sql = " SELECT * FROM sys_notice ";
		return super.getBySql(sql,Notice.class);
	}
	/**带条件获取数据*/
	@SuppressWarnings("unchecked")
	@Override
	public List<Notice> getNoticeByParam(String sql, String[] params, Object[] values) {
		return super.getBySql(sql, params, values, Notice.class);
	}
	
	/**
	 * 获取全部 条数
	 */
	@Override
	public Integer getAllNoticeNum() {
		return super.getTotalCount(" SELECT * FROM sys_notice ", null, null, QlEnum.SQL);
	}
	

	@Override
	/**
	 * 根据条件获取条数
	 */
	public Integer getNoticeNum(String sql,String[] params, Object[] values){
		return super.getTotalCount(sql, params, values, QlEnum.SQL);
	}
	
	/**根据条件 分页获取 数据*/
	@Override
	public List<Notice> getNoticeByPage(String qlString, String[] params, Object[] values, Integer top,
			Page pageModel,  QlEnum qlType, PageEnum pageType) {
			Page page = super.getByHibernateQuery(qlString, params, values, top, pageModel, Notice.class, QlEnum.SQL, pageType);
		return page.getRecord();
	}
	
	/**根据ID 获取单个数据*/
	@Override
	public Notice getNoticeByID(String id) {
		return super.get(Notice.class, id);
	}
	
	/**保存*/
	@Override
	public String saveNotice(Notice notice) {
		return super.save(notice);
	}

	/**
	 * 根据id删除
	 * @param id
	 */
	@Override
	public Integer delNotice(String id) {
		String sql = "DELETE FROM sys_notice WHERE id = '"+ id +"' ";
		return super.executeQL(sql, new String[]{}, new Object[]{}, QlEnum.SQL);
	}

	@Override
	/**
	 * 批量删除，id 是 , 组合的
	 * @param id
	 */
	public Integer delNotice(String[] ids) {
		String delIds = "";
		if(ids.length>0){
			for(String id : ids){
				delIds += "'"+id+"',";
			}
			delIds = delIds.substring(0,(delIds.length()-1));
		}
		String sql = "DELETE FROM sys_notice WHERE id in ("+ delIds +") ";
		return super.executeQL(sql, new String[]{}, new Object[]{}, QlEnum.SQL);
	}

	/**修改*/
	@Override
	public String updateNotice( Notice notice) {
		return super.update(notice);
	}

	
}
